import java.util.*;
public class Player
{
    private int strength =40;
    private int money = 40;
    private int protect = 0;
    private boolean nessary = false;
    private int purchase = 0;
    private Map<String, Thing> bag = new HashMap<>();
    
    public void step() {
        strength -= 10;
        if (isDead()) {
            System.out.println("您感觉到头昏! 你死亡了!");
            System.out.println("游戏结束！ 很遗憾，你失败了");
            System.exit(0);
        }
    }
    
    public void pick(Thing thing) {
        bag.put(thing.getName(), thing);
        
        
    }
    
    public void eat(String name) {
       Thing thing = bag.get(name);
       if(thing != null) {
           strength += thing.getEnergy();
            
           if(strength >100) {
                strength = 100;
                
           }
       }
       else {
           System.out.println("使用补给品失败! 请先查看背包中有无该物品");
       }
    }
    public void use(String name){
        Thing thing = bag.get(name);
       if(thing != null) {
           System.out.println("恭喜你变成高富帅！");
           System.exit(0);
       }
        else {
            System.out.println("抱歉! 使用前请查看背包中是否存在该物件!");
        }
        bag.remove(name);
    }
    public void hurt(int damage) {
        strength -= damage;
        if (isDead()) {
            System.out.println("您感觉到头昏! 你晕了过去! 深渊迷宫消失，你被传送到了家中");
            System.out.println("游戏结束！ 很遗憾，你失败了");
            System.exit(0);
        }
    }
    
    public boolean isDead() {
        return strength <= 0; 
    }
    
    public void addToBag(Thing thing) {
        if (thing == null) {
            System.out.println("没东西可以捡!");
        }
        else if ( "X试剂" == thing.getName()) {
            nessary = true;
            pick(thing);
            System.out.println( thing.getName() +"成功加入背包!");
        }
        else {
            pick(thing);
            System.out.println( thing.getName() +"成功加入背包!");
        }
    }
    public void checkAndPrint() {
        if (bag.isEmpty()) {
            System.out.println("你的背包里面啥子都没得!");
        }
        else {
            System.out.println("你的背包有如下东西:");
            for (String key : bag.keySet()) {
                System.out.print("名称:   "+bag.get(key).getName() + "   回复能量" );
                
            }
           
        }
    }
    
    
    public void eatThing(Command command) {
        if(!command.hasSecondWord()) {
            System.out.println("吃什么鬼?");
            return;
        }
        
        String key = command.getSecondWord();
        if (bag.containsKey(key)) {
            eat(key);
            System.out.println("你的能量回复了" + bag.get(key).getEnergy()+"点!");
            System.out.println("你当前的能量是" + strength + "点!");
            System.out.println("但是你吃成胖子了!");
        }
        else {
            System.out.println("抱歉! 使用前请查看背包中是否存在该物件!");
            System.out.println("你可以通过'check'命令来查看背包中的物品!");
        }
        bag.remove(key);
    }
    
    public void use() {
        System.out.println("使用成功!你已经变成高富帅");
        System.out.println("游戏结束!");
        System.exit(0);
    }
    
    
    public int getStrength() {
        return this.strength;
    }
    
}
